<?php
namespace app\manage\controller;
use think\Db;
use think\Exception\PDOException;
use think\Controller;
class Affairbase extends Controller{
	function __construct() {
		session('user.id', 20);
	}
	
	static $typeMap = [2 => '产品订单', 3 => '工程订单'];
	//事务类型表
	private static $affairMap = [2 => 'AffairOrder', 3 => 'AffairEngineering'];
	
	//事务创建
	public function affairCreate($type) {
		$class = '\app\manage\\'.self::$affairMap[$type];
		$affair = new $class;
		show($affair->apply());
	}
	
	//通过姓名或者职务查人
	public function queryPerson(){
		$duty = input('?post.duty') ? input('post.duty') : false;
		$name = input('?post.name') ? input('post.name') : false;
		$userModel = new \app\common\model\User();
	}
	
	
	//我的订单列表
	public function myOrderList(){
		$state = input('post.state');
		if($state != 2) $where['state'] = $state;
		$page = input('?post.page') ? input('post.page') : 1;
		$pageSize = 10;
		$where['create_by'] = session('user.id');
		$rows = Db::table('affair_table')
						->field('id,create_t,type,order_no,order_name,state')
						->where($where)
						->order('id desc')
						->limit(--$page*$pageSize, $pageSize)
						->select();
		if(!$rows) show(1, '操作成功');
		
		foreach ($rows as $v){
			if($v['type'] == 2){
				$data[] = [
						'typeName' => self::$typeMap[$v['type']],
						'title' => '订单号:'.$v['order_no'],
						'time' => $v['create_t'],
						'state' => $v['state'],
						'url' => url('wechat/Cons/busininfos', ['id' => $v['id']])
				];
			}
			
			if($v['type'] == 3){
				$data[] = [
						'typeName' => self::$typeMap[$v['type']],
						'title' => '工程名:'.$v['order_name'],
						'time' => $v['create_t'],
						'state' => $v['state'],
						'url' => url('wechat/Cons/businlistdetail', ['id' => $v['id']])
				];
			}
		}
		show(1, '操作成功', $data); 
	}
	
	//我的评审列表
	public function myJuryList(){
		$type = input('post.type');
		if($type != 0) $where['type'] = $type;
		$page = input('?post.page') ? input('post.page') : 1;
		$pageSize = 10;
		
		$where['cur_chief'] = session('user.id');
		$where['state'] = -1;
		$rows = Db::table('affair_table')
					->field('id,create_t,type,order_no,order_name')
					->where($where)
					->order('id desc')
					->limit(--$page*$pageSize, $pageSize)
					->select();
		
		if(!$rows) show(1, '操作成功');
		
		foreach ($rows as $v){
			if($v['type'] == 2){
				$data[] = [
						'type' => 2,
						'typeName' => self::$typeMap[$v['type']],
						'title' => '订单人:'.$v['order_name'],
						'time' => $v['create_t'],
						'url' => url('wechat/Cons/oreview', ['id' => $v['id']])
				];
			}
			
			if($v['type'] == 3){
				$data[] = [
						'type' => 3,
						'typeName' => self::$typeMap[$v['type']],
						'title' => '工程名:'.$v['order_name'],
						'time' => $v['create_t'],
						'url' => url('wechat/Cons/ereview', ['id' => $v['id']])
				];
			}
		}
		
		show(1, '操作成功', $data);
	}
	
	
}
